package demo3;

class Shape {
    public void draw() {
        System.out.println("画图形");
    }
}

class Flower extends Shape {
    @Override
    public void draw() {
        System.out.println("❀");
    }
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}

class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("⚪");
    }
}

public class Test {

    public static void drawShapes1() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void drawShapes2() {
/*        Cycle cycle = new Cycle();
        Shape shape = cycle;*/
        Shape[] shapes = {new Cycle(),new Rect(), new Cycle(), new Rect(), new Flower()};
        for(Shape shape : shapes) {
            shape.draw();
        }
    }

    public static void drawMap(Shape shape) {
        shape.draw();
    }
    public static void main(String[] args) {
/*        Flower flower = new Flower();
        drawMap(flower);
        Rect rect = new Rect();
        drawMap(rect);
        Cycle cycle = new Cycle();
        drawMap(cycle);*/
        drawShapes2();
    }
}
